package com.zxmr.domain.service;

import java.sql.SQLException;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.zxmr.CommonInit;
import com.zxmr.db.DBManager;
import com.zxmr.domain.account.Company;
import com.zxmr.domain.account.User;

public class CompanyService {

	DBManager db = CommonInit.getDBManager();
	
	public boolean addCompany(Company company,User admin) 
	{
		SqlMapClient map = db.getMapper();
		try {
			map.startTransaction();
			int id = (Integer)map.insert("company.add", company);
			admin.setCompany(id);
			map.insert("user.add", admin);
			map.commitTransaction();
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}finally{
			try {
				map.endTransaction();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public Company findByName(String name)
	{
		try {
			Company company = (Company)db.getMapper().insert("company.findByName", name);
			return company;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
}
